package com.litemall.order.controller;

import com.litemall.order.service.OrderService;
import com.litemall.pojo.Order;
import com.litemall.response.UserOrderDTO;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : Areli
 * @date : 2020/4/19 20:43
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    OrderService  orderService;
    @Autowired
    Mapper dozerMapper;

    @GetMapping("findOrder")
    public List<Order> findOrder(@RequestParam("username") String username){
        return orderService.findListByUserName(username);
    }

    @GetMapping("findUserOrder")
    public List<UserOrderDTO> findUserOrder(@RequestParam("username")String username){
        List<Order> orderList = orderService.findListByUserName(username);
        List<UserOrderDTO> resultList = new ArrayList<>();
        for (Order order : orderList) {
            //属性拷贝
            UserOrderDTO userOrderDTO = dozerMapper.map(order, UserOrderDTO.class);
            resultList.add(userOrderDTO);
        }
        return resultList;
    }
}
